package stream流第一遍.demo10;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * @author wql
 * @version 1.0
 * @date 2022/11/5 21:01
 */

public class Test {
    public static void main(String[] args) {
        List<Wql> list = new ArrayList<>();
        list.add(new Wql("张二",12,"男"));
        list.add(new Wql("李三",11,"男"));
        list.add(new Wql("王麻",3,"男"));
        list.add(new Wql("大炮",7,"男"));
        list.add(new Wql("益达",90,"男"));
        list.add(new Wql("只因",1000000001,"女"));

        //搜集为一个新的集合
       // Set<String> set = list.stream().filter(item -> item.getAge() > 20).map(item -> item.getName()).collect(Collectors.toSet());
      //  System.out.println("set = " + set);


      //  Map<String, Wql> collect = list.stream().filter(item -> item.getAge() > 10).filter(item -> item.getSex() == "男").collect(Collectors.toMap(item -> item.getName(), item -> item));
       // System.out.println("collect = " + collect);

        //分组操作
        Map<String, List<Wql>> collect = list.stream().collect(Collectors.groupingBy(item -> item.getSex()));
        System.out.println("collect = " + collect);
    }
}
class Wql{
    private String name;
    private Integer age;
    private String sex;

    public Wql(String name, Integer age, String sex) {
        this.name = name;
        this.age = age;
        this.sex = sex;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    @Override
    public String toString() {
        return "Wql{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", sex='" + sex + '\'' +
                '}';
    }
}


